#include <Windows.h>
#include <gl\GL.h>

void drawGrid(float size, float step)
{
    glBegin(GL_LINES);

    glColor3f(0.3f, 0.3f, 0.3f);
    for(float i=step; i <= size; i+= step)
    {
        glVertex3f(-size, 0,  i);   // lines parallel to X-axis
        glVertex3f( size, 0,  i);
        glVertex3f(-size, 0, -i);   // lines parallel to X-axis
        glVertex3f( size, 0, -i);

        glVertex3f( i, 0, -size);   // lines parallel to Z-axis
        glVertex3f( i, 0,  size);
        glVertex3f(-i, 0, -size);   // lines parallel to Z-axis
        glVertex3f(-i, 0,  size);
    }

    // x-axis
    glColor3f(0.5f, 0, 0);
    glVertex3f(-size, 0, 0);
    glVertex3f( size, 0, 0);

    // z-axis
    glColor3f(0,0,0.5f);
    glVertex3f(0, 0, -size);
    glVertex3f(0, 0,  size);

    glEnd();
}

void drawBox(float sideLength)
{
	glPushMatrix();
		
		glBegin(GL_QUADS);
			// front
			glColor3f(1,0,0);
			glVertex3f(-sideLength/2, -sideLength/2, sideLength/2);
			glVertex3f( sideLength/2, -sideLength/2, sideLength/2);
			glVertex3f( sideLength/2,  sideLength/2, sideLength/2);
			glVertex3f(-sideLength/2,  sideLength/2, sideLength/2);
			// back
			glColor3f(0,1,0);
			glVertex3f(-sideLength/2, -sideLength/2, -sideLength/2);
			glVertex3f( sideLength/2, -sideLength/2, -sideLength/2);
			glVertex3f( sideLength/2,  sideLength/2, -sideLength/2);
			glVertex3f(-sideLength/2,  sideLength/2, -sideLength/2);
			// left
			glColor3f(0,0,1);
			glVertex3f(-sideLength/2, -sideLength/2, sideLength/2);
			glVertex3f(-sideLength/2,  sideLength/2, sideLength/2);
			glVertex3f(-sideLength/2,  sideLength/2, -sideLength/2);
			glVertex3f(-sideLength/2, -sideLength/2, -sideLength/2);
			// right
			glColor3f(1,1,0);
			glVertex3f( sideLength/2, -sideLength/2, sideLength/2);
			glVertex3f( sideLength/2,  sideLength/2, sideLength/2);
			glVertex3f( sideLength/2,  sideLength/2, -sideLength/2);
			glVertex3f( sideLength/2, -sideLength/2, -sideLength/2);
			// top
			glColor3f(1,0,1);
			glVertex3f(-sideLength/2,  sideLength/2, sideLength/2);
			glVertex3f( sideLength/2,  sideLength/2, sideLength/2);
			glVertex3f( sideLength/2,  sideLength/2, -sideLength/2);
			glVertex3f(-sideLength/2,  sideLength/2, -sideLength/2);
			// bottom
			glColor3f(0,1,1);
			glVertex3f(-sideLength/2, -sideLength/2, sideLength/2);
			glVertex3f( sideLength/2, -sideLength/2, sideLength/2);
			glVertex3f( sideLength/2, -sideLength/2, -sideLength/2);
			glVertex3f(-sideLength/2, -sideLength/2, -sideLength/2);
		glEnd();

	glPopMatrix();
}

void drawQuad(float len)
{
	glPushMatrix();
		
		glBegin(GL_QUADS);
			glVertex3f(-len/2, -len/2, -5);
			glVertex3f( len/2, -len/2, -5);
			glVertex3f( len/2, len/2, -5);
			glVertex3f(-len/2, len/2, -5);
		glEnd();

	glPopMatrix();
}

void drawQuadWithTexture(float len, GLuint texId)
{
	glPushMatrix();
		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D, texId);

		glBegin(GL_QUADS);
			glTexCoord2f(0, 0); glVertex3f(-len/2, -len/2, -5);
			glTexCoord2f(1, 0); glVertex3f( len/2, -len/2, -5);
			glTexCoord2f(1, 1); glVertex3f( len/2, len/2, -5);
			glTexCoord2f(0, 1); glVertex3f(-len/2, len/2, -5);
		glEnd();
		glDisable(GL_TEXTURE_2D);
	glPopMatrix();
}